﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="ThietBiSo.LinQDB" %>
<%@ Import Namespace="ThietBiSo.Models" %>
<!DOCTYPE html>
<html>
<head runat="server">
    <title>Danh mục con</title>
    <script src="<%= Url.Content("~/Content/jsAdmin/webservice/jquery.js")%>" type="text/javascript"></script>
    <script src="<%= Url.Content("~/Content/jsAdmin/webservice/jscontroller.js")%>" type="text/javascript"></script>
    <script src="<%= Url.Content("~/ckeditor/ckeditor.js") %>" type="text/javascript"></script>
    <script src="<%= Url.Content("~/ckfinder/ckfinder.js")%>" type="text/javascript"></script>
    <link href="<%= Url.Content("~/Content/cssAdmin/admin.css")%>" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        function submitForm() {
            if (checkForm()) {
                document.forms[0].submit();
            }
        }

        function checkForm() {
            var flag = true;
            var F = document.forms[0];
            var DanhMucCon = document.getElementById("TenDMCon").value;

            if (DanhMucCon == null || DanhMucCon == "") {
                alert("Nhập tên danh mục con !!!");
                F.DanhMucCon.focus();
                flag = false;

            }
            return flag;
        }
        function danhmuccon_delete(ma) {
            var cnf = window.confirm("Bạn chắc chắn xóa?");
            if (cnf) {
                $.ajax({
                    type: "POST",
                    url: '<%=Url.Action("DeleteDMC") %>',
                    cache: false,
                    async: false,
                    dataType: "json",
                    data: { ma: ma },
                    success: function (result) {
                        if (result.length == 0) { // ko tồn tại                        
                            //                            alert("Xóa dữ liệu thành công.");
                            window.location.reload();
                        }
                        else {
                            alert(result);
                        }
                    }
                });
            }

        }
        function danhmuccon_hienthi(ma) {

            $.ajax({
                type: "POST",
                url: '<%=Url.Action("HienThiDMC") %>',
                cache: false,
                async: false,
                dataType: "json",
                data: { ma: ma },
                success: function (result) {
                }
            });
        }
    </script>
</head>
<body>
    <div style="float: left; margin-left: 20px; margin-top: 10px; margin-bottom: 10px;">
        <% using (Html.BeginForm("danhmuccon", "danhmuc", FormMethod.Post, new { @enctype = "multipart/form-data" }))
           { %>
        <%: Html.ValidationSummary(true)%>
        <table width="600">
            <tr>
                <td class="tableLabel">
                    Danh mục con
                </td>
                <td class="tableField">
                    <%:Html.TextBox("TenDMCon", null, new { @style = "width:300px" })%>
                </td>
                <td>
                    <input type="button" value="Thêm" class="btn" onclick="submitForm();" />
                </td>
            </tr>
        </table>
        <%:Html.Hidden("MaDM", ViewData["urlid"])%>
        <%} %>
    </div>
    <div style="float: left; margin-left: 20px; clear: both">
        <table width="600" cellpadding="2" cellspacing="0" border="0">
            <tr>
                <td colspan="2">
                    <table id="bang_admin" class="tbl colorize" width="600" border="0">
                        <tbody>
                            <tr>
                                <th align="center" width="20px">
                                    TT
                                </th>
                                <th align="center" width="50">
                                    Danh mục con
                                </th>
                                <th width="10">
                                    Hiển thị
                                </th>
                                <th align="center" width="30">
                                    Xóa
                                </th>
                            </tr>
                        </tbody>
                        <tbody>
                            <% foreach (DanhMucCon item in (List<DanhMucCon>)ViewData["danhmuccons"])
                               {               
                            %>
                            <tr class="tb_hienthi">
                                <td align="center" valign="middle">
                                    <input type="text" disabled="disabled" style="width: 20px" class="orderbox" value="<%:item.ThuTu %>"
                                        maxlength="4" id="thutu" />&nbsp;
                                </td>
                                <td align="left">
                                    <a href="<%=Url.Action("EditDMCon","danhmuc", new { id = item.MaDMCon, cbNhom= item.MaDanhMuc } ) %>">
                                        <%: item.TenDMCon%>
                                    </a>
                                </td>
                                <td align="center">
                                    <%if (item.HienThi == false)
                                      {
                                    %>
                                    <a href="javascript:danhmuccon_hienthi(<%:item.MaDMCon%>);">
                                        <input type="checkbox" />
                                    </a>
                                    <%}
                                      else
                                      {%>
                                    <a href="javascript:danhmuccon_hienthi(<%:item.MaDMCon%>);">
                                        <input type="checkbox" checked="checked" /></a>
                                    <%} %>
                                </td>
                                <td align="center">
                                    <a href="javascript:danhmuccon_delete(<%:item.MaDMCon %>);">
                                        <img src="../../Content/imagesAdmin/images/pic_trash.gif" alt="" /></a>
                                </td>
                            </tr>
                            <% } %>
                        </tbody>
                    </table>
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
